home *** CD-ROM | disk | FTP | other *** search
/ LEGO Island 2 Rolling Demo / legoisland2.bin / Xtras / DirectMedia Xtra Behaviors.cst / 00006_Script_Volume slider < prev    next >
Text File  |  2000-01-16  |  6KB  |  176 lines

  1. -- DirectMedia Xtra Volume Slider
  2.  
  3.  
  4.  
  5. property pDuration, pMovieTime, VideoSprite
  6.  
  7.  
  8. property extentSprite
  9. property hiliteMember  -- looks like the handle plus hilite graphics
  10. -- also holds the member of handle while hilited
  11.  
  12. property tracking
  13. property newLocH
  14. property newLocV
  15.  
  16.  
  17. property dynamic   -- if true and sending true, sends value while tracking
  18.  
  19. property min, max  -- the range the slider maps to
  20. property valrange  -- the difference of max and min, set on begin
  21. property minScreen, maxScreen -- calculated from the screen coords of the extent
  22. property currentScreenVal -- the data point in screen coords, set in tracking
  23. property extentlength -- in screen coords, set on begin
  24.  
  25. property CurrentVal
  26.  
  27. on getPropertyDescriptionList
  28.   if the currentspritenum = 0 then 
  29.     set memdefault = 0 
  30.   else
  31.     set memref = the member of sprite the currentspritenum
  32.     set memdefault = member (the membernum of member memref + 1) 
  33.   end if
  34.   
  35.   
  36.   set description = [:]
  37.   
  38.   addprop description, #VideoSprite, [#default: 1, #format:#integer, #comment: "Video Sprite:"]
  39.   
  40.   addprop description, #extentSprite, [#default: 1, #format:#integer, #comment: "Extent Sprite:"]
  41.   
  42.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,#comment: "Hilite Member:"]
  43.   
  44.  
  45.   addprop description, #dynamic, [#default: 1, #format:#boolean,#comment: "Dynamic:"]
  46.   
  47.   return description
  48. end
  49.  
  50. on getBehaviorDescription
  51.   return "Drag to slider 'handle' to enable control of volume.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ò Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ò Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite."  & RETURN & "ò Hilite Member -  Member to display while handle is being dragged."  & RETURN & "ò Dynamic - If set, volume will be updated while handle is dragged, else when handle is released."
  52. end
  53.  
  54. on compute_val me
  55.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  56.   set val = 0.0
  57.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  58.   set val = val * the valrange of me
  59.   set val = val + the min of me
  60.   return val
  61. end
  62.  
  63. on send_the_val me, val
  64.   -- sets the digital video volume to the val * paramter 
  65.   set pMovieTime = val * pDuration
  66.   setvolume(sprite VideoSprite, pMovieTime-100)
  67. end
  68.  
  69.  
  70. on beginSprite me
  71.   
  72.   set pDuration = 100
  73.   
  74.   set the min of me = 0.0
  75.   set the max of me = 1.0
  76.   
  77.   --
  78.   set handle = the spritenum of me
  79.   set the tracking of me = FALSE
  80.   set the newLocH of me = the locH of sprite handle
  81.   set the newLocV of me = the locV of sprite handle
  82.   
  83.    
  84.     set the newLocV of me = the locV of sprite the extentSprite of me
  85.     set the minScreen of me = the left of sprite the extentSprite of me
  86.     set the maxScreen of me = the right of sprite the extentSprite of me
  87.   
  88.   set the locH of sprite handle to the newLocH of me
  89.   set the locV of sprite handle to the newLocV of me
  90.   
  91.   set the valrange of me = the max of me - the min of me
  92.   set the extentlength of me = the maxScreen of me - the minScreen of me
  93.   
  94.   
  95. end
  96.  
  97. on prepareFrame me
  98.  
  99.   
  100.   if tracking then
  101.     set handle = the spriteNum of me
  102.     set extent =  the extentSprite of me
  103.     
  104.   
  105.       set the newLocH of me = the mouseH
  106.       set the newLocV of me = the locV of sprite extent
  107.       if the newLocH of me < the left of sprite extent then
  108.         set the newLocH of me = the left of sprite extent
  109.       end if
  110.       if the newLocH of me > the right of sprite extent then
  111.         set the newLocH of me = the right of sprite extent
  112.       end if
  113.       
  114.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  115.       
  116.     
  117.     set the locH of sprite handle to the newLocH of me
  118.     set the locV of sprite handle to the newLocV of me
  119.     
  120.     if the dynamic of me then
  121.       send_the_val me, compute_val (me)
  122.     end if
  123.     
  124.   else   --  end if tracking, control slider position by movieTime
  125.     
  126.     set x = float(getvolume(sprite VideoSprite)+100)/ float(pDuration)
  127.     
  128.     
  129.     set handle = the spriteNum of me
  130.     set extent =  the extentSprite of me
  131.     
  132.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  133.       set the newLocH of me = screenX
  134.       set the newLocV of me = the locV of sprite extent
  135.       if the newLocH of me < the left of sprite extent then
  136.         set the newLocH of me = the left of sprite extent
  137.       end if
  138.       if the newLocH of me > the right of sprite extent then
  139.         set the newLocH of me = the right of sprite extent
  140.       end if
  141.       
  142.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  143.     
  144.     set the locH of sprite handle to the newLocH of me
  145.     set the locV of sprite handle to the newLocV of me
  146.     
  147.   end if
  148.   
  149.   
  150. end
  151.  
  152. on mouseDown me 
  153.   set tracking = TRUE
  154.   set temp = the member of sprite the spritenum of me
  155.   set the member of sprite the spritenum of me = member the hiliteMember of me
  156.   set the hiliteMember of me = temp
  157. end
  158.  
  159. on mouseUp me
  160.   set tracking = FALSE
  161.   set temp = the member of sprite the spritenum of me
  162.   set the member of sprite the spritenum of me = member the hiliteMember of me
  163.   set the hiliteMember of me = temp
  164.  
  165. end
  166.  
  167. on mouseUpOutside me
  168.   set tracking = FALSE
  169.   set temp = the member of sprite the spritenum of me
  170.   set the member of sprite the spritenum of me = member the hiliteMember of me
  171.   set the hiliteMember of me = temp 
  172. end
  173.  
  174.  
  175.  
  176.